<template>
	<view class="user">
		<template v-if="yrPageConfig && user">
			<view class="back-button" @click="clickBack">
				<text class="iconfont icon-arrow-left-bold"></text>
			</view>
			<view class="banner" :style="'width: 100%;background: #000 url('+(user.banner?user.banner:yrPageConfig.backgroundImage)+');background-size: 100%;background-repeat: no-repeat;background-position: center;'">
				<view class="user-info">
					<view class="bar-height"></view>
					<view class="avatar" @click="$_To('public/image?url='+user.avatar)">
						<image :src="user.avatar" mode="widthFix"></image>
					</view>
					<view class="nickname">
						<text class="text">{{user.nickname}}</text>
						<template v-if="user.gender != 1">
							<text
								:style="user.gender==3?'color: #ff00ff;':'color: #409EFF;'"
								:class="user.gender==3?'iconfont icon-nv':'iconfont icon-nan'"></text>
						</template>
					</view>
					<view class="bio">{{user.bio}}</view>
				</view>
			</view>
			<view class="stats">
				<view class="role-name">
					<text :style="'color:'+user.nicknameColor+';'">{{user.roleName}}</text>
				</view>
				<view class="for">
					<text class="text">帖子</text>
					<text class="digit">{{user.stats.postPublishCount}}</text>
				</view>
				<view class="for">
					<text class="text">评论</text>
					<text class="digit">{{user.stats.commentPublishCount}}</text>
				</view>
				<view class="for">
					<text class="text">粉丝</text>
					<text class="digit">{{user.stats.followMeCount+user.stats.postFollowCount}}</text>
				</view>
				<view class="for">
					<text class="text">获赞</text>
					<text class="digit">{{user.stats.likeMeCount+user.stats.postLikeCount}}</text>
				</view>
				<view class="right">
					<view @click="clickInteraction('follow')" v-if="user.interaction.followSetting" :style="user.interaction.followStatus?'background: #F56C6C;':''">
						<text :style="user.interaction.followStatus?'color: #FFF;':''" class="iconfont icon-aixin"></text>
					</view>
					<view @click="clickInteraction('like')" v-if="user.interaction.likeSetting" :style="user.interaction.likeStatus?'background: #409EFF;':''">
						<text :style="user.interaction.likeStatus?'color: #FFF;':''" class="iconfont icon-good"></text>
					</view>
					<view @click="clickPrivateChat" v-if="user.conversation.status">
						<text class="iconfont icon-pinglun"></text>
					</view>
				</view>
			</view>
			<view class="tab-menu">
				<view
					@click="clickTabMenu(1)"
					:class="hover == 1?'for hover':'for'">
					<text class="text">Ta 帖子</text>
					<view></view>
				</view>
				<view
					@click="clickTabMenu(2)"
					:class="hover == 2?'for hover':'for'">
					<text class="text">Ta 回复</text>
					<view></view>
				</view>
				<!-- <view
					@click="clickTabMenu(3)"
					:class="hover == 3?'for hover':'for'">
					<text class="text">Ta 收藏</text>
					<view></view>
				</view>
				<view
					@click="clickTabMenu(4)"
					:class="hover == 4?'for hover':'for'">
					<text class="text">Ta 点赞</text>
					<view></view>
				</view>
				<view
					@click="clickTabMenu(5)"
					:class="hover == 5?'for hover':'for'">
					<text class="text">Ta 关注</text>
					<view></view>
				</view> -->
			</view>
			<template v-if="hover == 1">
				<list-concise
					v-for="item in listConcise"
					:style="'order:'+item.order+';'"
					listGid=""
					listHid=""
					:Item="item"
					:YrConfig="yrConfig&&yrConfig.blockGroups"></list-concise>
			</template>
			<template v-if="hover == 2">
				<list-comment
					v-for="item in listComment"
					:style="'order:'+item.order+';'"
					:Item="item"></list-comment>
			</template>
			<template v-if="hover == 3">
				333
			</template>
			<template v-if="hover == 4">
				444
			</template>
			<template v-if="hover == 5">
				555
			</template>
		</template>
		<template v-else>
			<view style="padding: 100rpx 0;">
				<public-loading></public-loading>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				yrPageConfig:null,
				user:null,
				hover:1,
				listConcise:[],
				listComment:[],
				yrConfig:null,
			}
		},
		onLoad(e) {
			this.Uid = e.uid;
			this.getYrConfig();
		},
		methods: {
			getYrConfig(){
				uni.request({
					url:this.$_Config() + "Config.json",
					method:'GET',
					success: (res) => {
						this.yrConfig = res.data;
						this.getConfig();
					}
				})
			},
			getConfig(){
				uni.request({
					url:this.$_Config() + "my.json",
					method:"GET",
					success: (res) => {
						this.yrPageConfig = res.data;
						this.getUser();
					}
				})
			},
			// 获取用户详情
			getUser(){
				this.$_Request(
					"GET","/api/v2/user/" + this.Uid + "/detail",{},
					(res) => {
						this.user = res.data.data.detail;
						this.getMyPost();
					}
				)
			},
			// 点击，操作用户
			clickInteraction(type){
				uni.showLoading();
				this.$_Request(
					"POST","/api/v2/user/mark",
					{
						"interactionType":type,
						"markType":"user",
						"fsid":this.Uid
					},
					(res) => {
						uni.hideLoading();
						if(res.data.code == 0){
							this.getConfig();
						}else{
							uni.showToast({
								title:res.data.message,
								icon:"none",
								duration:1000
							});
						}
					}
				)
			},
			// 点击，私聊对话
			clickPrivateChat(){
				uni.showLoading();
				this.$_Request(
					"POST","/api/v2/conversation/send-message",
					{
						"uidOrUsername":this.Uid+'',
						"message":'Hello~~'
					},
					(res) => {
						uni.hideLoading();
						if(res.data.code == 0){
							uni.switchTab({
								url: "/pages/notification/notification"
							});
						}else{
							uni.showToast({
								title:res.data.message,
								icon:"none",
								duration:1000
							});
						}
					}
				)
			},
			// 点击，切换卡
			clickTabMenu(e){
				this.hover = e;
				if(this.hover == 1){
					this.getMyPost();
				}
				if(this.hover == 2){
					this.getMuComment();
				}
			},
			// 获取，我的帖子
			getMyPost(){
				this.listConcise = [{
					"order": 400,
					"css": "padding:0 25rpx 0 25rpx;",
					"page": true,
					"query": {
						"mapId": "",
						"mapLng": "",
						"mapLat": "",
						"uidOrUsername": this.Uid,
						"hid": "empty",
						"gid": "empty",
						"includeSubgroups": 1,
						"allDigest": "",
						"digestState": "",
						"stickyState": "",
						"contentType": "",
						"createdDays": "",
						"createdDate": "",
						"createdDateGt": "",
						"createdDateLt": "",
						"likeCountGt": "",
						"likeCountLt": "",
						"followCountGt": "",
						"followCountLt": "",
						"blockCountGt": "",
						"blockCountLt": "",
						"commentCountGt": "",
						"commentCountLt": "",
						"orderType": "",
						"orderDirection": "",
						"blockGroups": "",
						"blockHashtags": "",
						"pluginRatingId": "",
						"pageSize": 15
					}
				}]
			},
			// 获取，我的评论
			getMuComment(){
				this.listComment = [{
					"order": 400,
					"css": "padding:0 25rpx 0 25rpx;",
					"page": true,
					"replyToComment": false,
					"query": {
						"mapId": "",
						"mapLng": "",
						"mapLat": "",
						"uidOrUsername": this.Uid,
						"pid": "",
						"cid": "",
						"hid": "",
						"gid": "",
						"includeSubgroups": 1,
						"sticky": "",
						"allDigest": "",
						"digestState": "",
						"contentType": "",
						"createdDays": "",
						"createdDate": "",
						"createdDateGt": "",
						"createdDateLt": "",
						"likeCountGt": "",
						"likeCountLt": "",
						"followCountGt": "",
						"followCountLt": "",
						"blockCountGt": "",
						"blockCountLt": "",
						"commentCountGt": "",
						"commentCountLt": "",
						"orderType": "commentTime",
						"orderDirection": "",
						"pageSize": 15
					}
				}]
			},
			// 点击，返回
			clickBack(){
				uni.navigateBack();
			},
		}
	}
</script>

<style lang="scss">
.user{
	position: relative;
	.back-button{
		position: absolute;
		top: var(--status-bar-height);
		left: 25rpx;
		z-index: 10;
		width: 70rpx;
		height: 70rpx;
		background-color:rgba(0,0,0,0.5);
		overflow: hidden;
		border-radius: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		text{
			color: #FFF;
		}
	}
	.banner{
		width: 100%;
		height: 700rpx;
		overflow: hidden;
		.user-info{
			width: 100%;
			.avatar{
				width: 220rpx;
				height: 220rpx;
				margin: 80rpx auto auto auto;
				border: 10rpx solid #FFF;
				box-shadow: 0 0 5rpx #000;
				border-radius: 100%;
				overflow: hidden;
			}
			.nickname{
				margin-top: 50rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				.text{
					color: #FFF;
					font-weight: bold;
					text-shadow: 0 0 5rpx #000;
					font-size: 50rpx;
					line-height: 50rpx;
				}
				.iconfont{
					text-shadow: 0 0 5rpx #000;
					color: $LanSe;
					font-size: 50rpx;
					line-height: 50rpx;
					//padding-left: 10rpx;
					font-weight: bold;
				}
			}
			.bio{
				margin: 30rpx 25rpx 0 25rpx;
				color: #FFF;
				text-shadow: 0 0 2rpx #000;
				display: -webkit-box;
				/*!autoprefixer:off*/
				-webkit-box-orient: vertical;
				/*autoprefixer:on*/
				-webkit-line-clamp: 3;
				overflow: hidden;
				text-align: center;
			}
		}
	}
	.stats{
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid $BianKuangSe;
		height: 80rpx;
		background: $BeiJingSe;
		.role-name{
			border-right: 1rpx solid $BianKuangSe;
			padding: 0 25rpx;
			margin-right: 25rpx;
			height: 32rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-shrink: 0;
		}
		.for{
			display: flex;
			align-items: center;
			justify-content: center;
			flex-flow: column;
			height: 80rpx;
			padding-right: 25rpx;
			flex-shrink: 0;
			text{
				font-size: 22rpx;
				line-height: 22rpx;
			}
			.text{
				padding-bottom: 10rpx;
				color: $ZhanWeiSe;
			}
		}
		.right{
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			padding-right: 10rpx;
			view{
				height: 60rpx;
				font-size: 28rpx;
				line-height: 28rpx;
				box-sizing: border-box;
				margin: 0 10rpx 0 0;
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 0 15rpx;
				border-radius: 10rpx;
				text{
					font-size: 34rpx;
					line-height: 34rpx;
				}
			}
			view:nth-child(1){
				border: 1rpx solid $HongSe;
				color: $HongSe;
			}
			view:nth-child(2){
				border: 1rpx solid $LanSe;
				color: $LanSe;
			}
			view:nth-child(3){
				border: 1rpx solid $HuangSe;
				background: $HuangSe;
				color: $YuanSe;
			}
		}
	}
	.tab-menu{
		width: 750rpx;
		height: 70rpx;
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid $BianKuangSe;
		.for{
			width: 150rpx;
			height: 70rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-flow: column;
			position: relative;
			.text{
				font-size: 28rpx;
				line-height: 28rpx;
				color: $ZhanWeiSe;
			}
		}
		.hover{
			.text{
				color: $YuanSe;
			}
			view{
				width: 40rpx;
				height: 10rpx;
				background: $HuangSe;
				border-radius: 100rpx;
				position: absolute;
				left: 55rpx;
				bottom: 15rpx;
			}
		}
	}
}
</style>
